import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class SwiperArea extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SwiperArea();
  }
}

class _SwiperArea extends State<SwiperArea> {
  List<String> imgList = ['images/thumbnail.jpg'];

  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: 300.0,
      child: Swiper(
        itemCount: imgList.length, //轮播图的数量
        itemBuilder: (BuildContext context, int index) {
          return Image.asset(
            imgList[index],
            fit: BoxFit.cover,
          );
        }, //使用预先定义好的Images列表构建轮播项
        autoplay: true, //是否自动轮播
        pagination: new SwiperPagination(
            builder: SwiperPagination.dots), //指示器样式，默认是小圆点，可以设置fraction、rect等形式
        // control: new SwiperControl(), //两侧箭头
        scrollDirection: Axis.horizontal,
        onTap: (index) => print('点击了第$index个'),
      ),
    );
  }
}
